"""
English:
This is my Progress Bar module.
中文：
这是我的进度条模块
"""
import time


class ProgressBar:
    """
    创建一个进度条实例
    """

    def __init__(self,
                 from_: int = 1,
                 to: int = 101,
                 bar_length: int = 10,
                 what: str = 'Progress'):
        """创建一个进度条实例

        参数:
            from_ (int, optional): 从哪个值开始递增. 默认为 1.
            to (int, optional): 递增至哪个值. 默认为 101.
            bar_length (int, optional): 进度条的长度(占据几个字符). 默认为 10.
            what (str, optional): 提示性文本. 默认为 'Progress'.
        """
        self.from_ = self.now = from_
        self.to = to
        self.len = bar_length
        self.notice = what

    def update(self, add: int = 1):
        """用于递增/刷新进度条

        参数:
            add (int, optional): 递增量. 默认为 1.
        """
        if self.now < self.to:
            self.now += add
        else:
            pass
        self.show()

    def distribution(self, what: str = 'Progress'):
        """修改进度条提示性文本

        参数:
            what (str, optional): 修改后的提示性文本. 默认为 'Progress'.
        """
        self.notice = what

    def show(self):
        """刷新进度条的显示
        """
        print(
            f'\r{self.notice}: [{'#' * int((self.len / (self.to - self.from_) * self.now))}{'-' * (self.len - int((self.len / (self.to - self.from_) * self.now)))}] {self.now}/{self.to}',
            end='')


if __name__ == '__main__':
    pb = ProgressBar()
    for i in range(1, 101):
        pb.update()
        time.sleep(0.1)
